package com.lakeworks.service.impl;

import com.lakeworks.domain.status.StaProduct;
import com.lakeworks.domain.vo.ProductFlow;
import com.lakeworks.mapper.StaProductMapper;
import com.lakeworks.service.IStaProductService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

import static com.lakeworks.common.enums.OprProductType.getName;
import static java.util.stream.Collectors.toList;

/**
 * 产品状态Service业务层处理
 *
 * @author lake
 * @date 2023-02-23
 */
@Service
public class StaProductServiceImpl implements IStaProductService {

    @Resource
    private StaProductMapper staProductMapper;

    /**
     * 查询产品状态
     *
     * @param id 产品状态主键
     * @return 产品状态
     */
    @Override
    public StaProduct selectStaProductById(Long id) {
        return staProductMapper.selectStaProductById(id);
    }

    /**
     * 查询产品状态列表
     *
     * @param staProduct 产品状态
     * @return 产品状态
     */
    @Override
    public List<StaProduct> selectStaProductList(StaProduct staProduct) {
        return staProductMapper.selectStaProductList(staProduct);
    }

    /**
     * 新增产品状态
     *
     * @param staProduct 产品状态
     * @return 结果
     */
    @Override
    public int insertStaProduct(StaProduct staProduct) {
        return staProductMapper.insertStaProduct(staProduct);
    }

    /**
     * 修改产品状态
     *
     * @param staProduct 产品状态
     * @return 结果
     */
    @Override
    public int updateStaProduct(StaProduct staProduct) {
        return staProductMapper.updateStaProduct(staProduct);
    }

    /**
     * 批量删除产品状态
     *
     * @param ids 需要删除的产品状态主键
     * @return 结果
     */
    @Override
    public int deleteStaProductByIds(Long[] ids) {
        return staProductMapper.deleteStaProductByIds(ids);
    }

    /**
     * 删除产品状态信息
     *
     * @param id 产品状态主键
     * @return 结果
     */
    @Override
    public int deleteStaProductById(Long id) {
        return staProductMapper.deleteStaProductById(id);
    }

    @Override
    public int deleteStaProductBystates(StaProduct staProduct) {
        return staProductMapper.deleteStaProductBystates(staProduct);
    }

    @Override
    public List<ProductFlow> statusByBarcode(String barcode) {
        List<ProductFlow> productFlows = staProductMapper.statusByBarcode(barcode);
        return productFlows.stream().map(productFlow -> productFlow.setDescription(getName(productFlow.getStatus()))).collect(toList());
    }

}
